package com.wokeMy.view.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wokeMy.view.interfa.MyItemClickListener;
import com.zhongcai.online.R;

import java.util.List;

/**
 * Created by Administrator on 2017-11-15.
 */

public class GGaoAdapter extends RecyclerView.Adapter<GGaoAdapter.ViewHolder>{
    private MyItemClickListener mItemClickListener;
    public List<String> mDataset;
    private LayoutInflater inflater;
    private Context context;
    private String lottertId;

    public GGaoAdapter(List<String> dataset, Context context,String lottertId) {
        super();
        mDataset = dataset;
        this.context=context;
        this.inflater=LayoutInflater.from(context);
        this.lottertId=lottertId;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view =inflater.inflate(R.layout.item_item_ball,null);
        ViewHolder holder = new ViewHolder(view, mItemClickListener);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int i) {

        switch (lottertId) {
            case "118":
                if (i==mDataset.size()-1){
                    Log.e("viewHolder","........");
                    viewHolder.mTextView.setBackgroundResource(R.mipmap.blue_ball_bg);
                }
                viewHolder.mTextView.setText(mDataset.get(i));
                break;
            case "106":
                if (i>=mDataset.size()-2){
                    Log.e("viewHolder","........");
                    viewHolder.mTextView.setBackgroundResource(R.mipmap.blue_ball_bg);
                }
                viewHolder.mTextView.setText(mDataset.get(i));
                break;
            default:
                break;
        }

        switch (lottertId) {
            case "123":
                switch (mDataset.get(i)) {
                    case "1":
                        viewHolder.mTextView.setBackgroundResource(R.mipmap.one_dice);
                        break;
                    case "2":
                        viewHolder.mTextView.setBackgroundResource(R.mipmap.two_dice);
                        break;
                    case "3":
                        viewHolder.mTextView.setBackgroundResource(R.mipmap.three_dice);
                        break;
                    case "4":
                        viewHolder.mTextView.setBackgroundResource(R.mipmap.four_dice);
                        break;
                    case "5":
                        viewHolder.mTextView.setBackgroundResource(R.mipmap.five_dice);
                        break;
                    case "6":
                        viewHolder.mTextView.setBackgroundResource(R.mipmap.six_dice);
                        break;
                    default:
                        viewHolder.mTextView.setBackgroundResource(R.mipmap.one_dice);
                        break;
                }
                break;

            default:
                break;
        }


//        viewHolder.mTextView.setTextColor(context.getResources().getColorStateList(R.color.black));
    }

    @Override
    public int getItemCount() {
        return mDataset.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        private MyItemClickListener mListener;
        public TextView mTextView;
        public ViewHolder(View itemView,MyItemClickListener myItemClickListener) {
            super(itemView);
            this.mListener = myItemClickListener;
            mTextView = (TextView) itemView.findViewById(R.id.ball_item_item_tv);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (mListener != null) {
                mListener.OnItemClick(v, getPosition());
            }
        }

    }
    public void setItemClickListener(MyItemClickListener myItemClickListener) {
        this.mItemClickListener = myItemClickListener;
    }
}
